﻿package code
{
	import flash.utils.Timer;
	
	public class PlayerWeapon extends GenericWeapon
	{
		// Timer used for cooldown
		protected var cooldownTimer:Timer;
		
		// Returns the player to which this weapon is attached
		protected function get PlayerObj():Player { return parent as Player; }

		public function PlayerWeapon(spawnX:int, spawnY:int, cooldownTimerDelay:int, bulletType:Class)
		{
			super(spawnX, spawnY, bulletType);
			
			cooldownTimer = new Timer(cooldownTimerDelay, 1);
		}
		
		public function fire()
		{
			if (!cooldownTimer.running)
			{
				var b:GenericBullet = super.fireBullet(0, -7);
				PlayerObj.CurrentLevel.addPlayerBullet(b);
				
				cooldownTimer.reset();
				cooldownTimer.start();
			}
		}
	}
}